var News = {}

News.init = function(articleType){
	News.initGrid(articleType);
}

News.initGrid = function(type){
	var url = context+'/manager/newsListData.action?articleType='+type;
	$('#newsList').datagrid({
		width:768,
		height:'auto',
		striped: true,
		url:context+'/manager/news!newsListData.action?articleType='+type,
		remoteSort: false,
		idField:'id',
		columns:[[
					{field:'title',title:'标题',width:169,align:'center'},
					{field:'keyWord',title:'关键字',width:116,align:'center'},
					{field:'authorName',title:'添加人',width:130,align:'center'},
					{field:'addTime',title:'添加时间',width:140,align:'center'},
					{field:'id',title:'操作',width:180,align:'center',formatter:function(value,rec){
						var rendHtml ="";
						if(rec.type ==0){
							rendHtml +="<a href='review-message!list.action?articleId="+rec.id+"'  style='color:blue' >查看评论</a> | ";
						}
						rendHtml += "<a href='news!input.action?id="+rec.id+"' style='color:blue' >修改</a> | <a onClick='News.deleteNews("+rec.id+","+type+")' style='color:blue'>删除</a>";
						return rendHtml;
					}}
				]],
		pagination:true,
		loadMsg:'正在加载数据,请等待...',
		rownumbers:true
	});
	var p = $('#newsList').datagrid('getPager');
	if (p){
		$(p).pagination({
			showPageList:false,
			beforePageText:'第',
			afterPageText:"页，共<font color='blue'> {pages} </font>页",
			displayMsg:"当前显示 <font color='red'>{from}</font> 到 <font color='red'>{to}</font> 条记录，共<font color='red'> {total} </font>条记录",
		});
	}
}

News.deleteNews=function(id,type){
	$.ajax({
		type:'POST',
		url:'news!delete.action',
		data:{'id':id},
		success:function(data){
			alert(data);
			News.initGrid(type);
		}
	})
}


